package test3.main;

import test3.bean.Employee;
import test3.controller.PageController;
import test3.controller.impl.PageControllerImpl;

import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JOptionPane;

public class AddEmployeeAction implements ActionListener {

	Index index;
	
	public AddEmployeeAction(Index in) {
		index = in;
	}

	private PageController controller=new PageControllerImpl();
	
	@Override
	public void actionPerformed(ActionEvent e) {

		String select = e.getActionCommand();
		if(select == "submit") {

			//得到一个Employee的数据
			Integer id= Integer.parseInt(index.addEmployeeIdText.getText());
			String name=index.addEmployeeNameText.getText();
			Integer sex=Integer.parseInt(index.addEmployeeGenderText.getText());
			Integer age=Integer.parseInt(index.addEmployeeAgeText.getText());
			Employee ee=new Employee(id,name,sex,age);


			System.out.println(ee);

			controller.updateOrInsert(ee);

			//添加之后的操作

			Toolkit.getDefaultToolkit().beep();
			JOptionPane.showMessageDialog(null, "Add success","Result",JOptionPane.PLAIN_MESSAGE);
		}
		else if(select == "reset"){
			index.card.show(index.panel, "addEmployee");
		}
		else {
			index.card.show(index.panel, "welcome");
		}
		
	}

}
